package experiment4;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author mazouri
 * @create 2021-11-05 19:35
 */
public class MaxMatching {
    public static void main(String[] args) {
        List<Integer> M = Arrays.asList(2, 2, 0, 5, 3, 5, 7, 4);
        List<Integer> A = new ArrayList<>();
        for (int i = 0; i < M.size(); i++) {
            A.add(i);
        }
        maxMatch(M, A);
        M.removeIf(integer -> integer == -1);
        System.out.println(M);
    }

    private static void maxMatch(List<Integer> M, List<Integer> A) {
        ArrayList<Integer> E = new ArrayList<>();
        for (Integer e : A) {
            if (!M.contains(e)) E.add(e);
        }

        if (E.isEmpty()) return;

        for (Integer e : E) {
            M.set(e, -1);
            A.remove(e);
        }

        maxMatch(M, A);
    }
}
